package com.example.recyclerimageload.adapter_flipper;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterViewFlipper;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.example.recyclerimageload.R;

import java.util.ArrayList;
import java.util.List;

public class AdapterFlipperActivity extends AppCompatActivity implements View.OnClickListener {
    private AdapterViewFlipper flipper;
    private Button prev;
    private Button next;
    private Button auto;
    private List<String> datas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_adapter_flipper);

        flipper = ((AdapterViewFlipper) findViewById(R.id.flipper));
        prev = ((Button) findViewById(R.id.prev));
        next = ((Button) findViewById(R.id.next));
        auto = ((Button) findViewById(R.id.auto));

        prev.setOnClickListener(this);
        next.setOnClickListener(this);
        auto.setOnClickListener(this);

        initData();

        int[] urls = new int[]{R.mipmap.a,R.mipmap.b,R.mipmap.c,R.mipmap.d,R.mipmap.e};
        FlipperAdapter adapter = new FlipperAdapter(this, datas);
        flipper.setAdapter(adapter);
    }

    private void initData() {
        datas = new ArrayList<>();
        datas.add("https://i0.hdslb.com/bfs/article/2e67484d1d5fe574c5356794055dc0f5d76acc73.jpg@942w_progressive.jpg");
        datas.add("https://i0.hdslb.com/bfs/article/121c9c1b617e4ac575668053444a374941f47e4e.jpg@942w_progressive.jpg");
        datas.add("https://i0.hdslb.com/bfs/article/bf716c8813da10dd507e940ca05b394f99e2ba29.jpg@942w_progressive.jpg");
        datas.add("https://i0.hdslb.com/bfs/article/e5475d5cbb8aa9502eab234b052433301ce3300a.jpg@942w_progressive.jpg");
        datas.add("https://i0.hdslb.com/bfs/article/9db4d7a9a4739413c7d108387a4b418f782030b9.jpg@942w_progressive.jpg");
        datas.add("https://i0.hdslb.com/bfs/article/3f91bdb98ab47ee5897817a5fca484290385906a.jpg@942w_progressive.jpg");
        datas.add("http://img.jj20.com/up/allimg/1114/0H120155P2/200H1155P2-8-1200.jpg");
        datas.add("http://img.jj20.com/up/allimg/1114/0H320120A7/200H3120A7-1-1200.jpg");
        datas.add("http://img.jj20.com/up/allimg/1011/12061G41459/1G206141459-9-1200.jpg");
        datas.add("http://img.jj20.com/up/allimg/1011/120GG04649/1G20G04649-1-1200.jpg");
        datas.add("http://pic.jj20.com/up/allimg/mn01/041219224443/1Z412224443-0.jpg");
        datas.add("http://pic1.win4000.com/wallpaper/2018-02-01/5a72c5405c709.jpg");
        datas.add("http://pic1.win4000.com/wallpaper/2018-02-01/5a72c542b31c3.jpg");
        datas.add("http://pic1.win4000.com/wallpaper/2018-02-01/5a72c54e3627f.jpg");
        datas.add("http://pic1.win4000.com/wallpaper/2018-02-01/5a72c5567e8f2.jpg");
        datas.add("http://pic1.win4000.com/wallpaper/2018-02-01/5a72c5600242a.jpg");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.prev:
                flipper.showPrevious();
                flipper.stopFlipping();
                break;
            case R.id.next:
                flipper.showNext();
                flipper.stopFlipping();
                break;
            case R.id.auto:
                flipper.startFlipping();
                break;
        }
    }
}
